<script setup>
import { ref } from 'vue';
import { useRouter, useRoute } from 'vue-router';

const router = useRouter();
const route = useRoute();
const isCollapse = ref(false);

// 侧边栏菜单列表
const menuList = [
  { path: '/dashboard', title: '首页仪表盘', icon: 'Odometer' },
  { path: '/member', title: '会员管理', icon: 'User' },
  { path: '/coupon', title: '优惠券管理', icon: 'Tickets' },
  { path: '/order', title: '订单管理', icon: 'ShoppingCart' },
  { path: '/reservation', title: '预约管理', icon: 'Calendar' },
  { path: '/recharge', title: '充值管理', icon: 'Money' },
  { path: '/voucher', title: '团购券管理', icon: 'Ticket' },
  { path: '/message', title: '消息通知', icon: 'Bell' },
  { path: '/finance', title: '财务管理', icon: 'Wallet' },
  { path: '/setting', title: '系统设置', icon: 'Setting' }
];

const toggleCollapse = () => {
  isCollapse.value = !isCollapse.value;
};

const logout = () => {
  router.push('/login');
};
</script>

<template>
  <div v-if="route.path === '/login'">
    <router-view />
  </div>
  <el-container v-else class="layout-container">
    <!-- 侧边栏 -->
    <el-aside :width="isCollapse ? '64px' : '220px'" class="aside-container">
      <div class="logo-container">
        <span v-if="!isCollapse">棋牌室管理系统</span>
      </div>
      <el-menu
        :default-active="route.path"
        class="el-menu-vertical"
        :collapse="isCollapse"
        background-color="#304156"
        text-color="#bfcbd9"
        active-text-color="#409EFF"
        router
      >
        <el-menu-item v-for="item in menuList" :key="item.path" :index="item.path">
          <el-icon><component :is="item.icon" /></el-icon>
          <template #title>{{ item.title }}</template>
        </el-menu-item>
      </el-menu>
    </el-aside>

    <!-- 主体内容 -->
    <el-container>
      <!-- 顶部导航 -->
      <el-header class="header-container">
        <div>
          <el-icon class="fold-icon" @click="toggleCollapse">
            <component :is="isCollapse ? 'Expand' : 'Fold'" />
          </el-icon>
        </div>
        <div class="header-right">
          <el-dropdown trigger="click">
            <span class="user-info">管理员 <el-icon><ArrowDown /></el-icon></span>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item>个人信息</el-dropdown-item>
                <el-dropdown-item>修改密码</el-dropdown-item>
                <el-dropdown-item divided @click="logout">退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </el-header>

      <!-- 内容区域 -->
      <el-main>
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<style scoped>
.layout-container {
  height: 100vh;
}
.aside-container {
  background-color: #304156;
  transition: width 0.3s;
}
.logo-container {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background-color: #263445;
}
.el-menu-vertical:not(.el-menu--collapse) {
  width: 220px;
}
.header-container {
  background-color: #fff;
  border-bottom: 1px solid #e6e6e6;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.fold-icon {
  font-size: 24px;
  cursor: pointer;
}
.user-info {
  display: flex;
  align-items: center;
  cursor: pointer;
}
</style>
